|
|
|
|
|
|
|
Example program Enlarge uses the same technique to enlarge an image. Load a picture file and enter a scale factor that is at least 1.0. Click the Enlarge button to make the program enlarge the image. |
|
|
|
|
|
|
|
|
Enlarging an image with PaintPicture can make the result appear blocky. PaintPicture can also cause problems when it reduces the size of an image. To make an image smaller, PaintPicture omits some of the pixels from the image. Unfortunately, it does not always pick the best pixels to omit. Sometimes it removes pixels that are important to the picture and the results look strange. This problem is called aliasing. |
|
|
|
|
|
|
|
|
In dithered images, where one color is placed on top of another to simulate a third, the reduction may remove most of the top color and leave the background color in ugly splotches. This sort of reduction also often removes pixels that shade a region to make colors blend smoothly. In that case, the edges of the region may become abrupt or jagged. |
|
|
|
|
|
|
|
|
Even worse, PaintPicture may remove large pieces of thin lines, thus making gaps appear. Example program Shrink, shown in Figure 7.15, draws a series of lines and then uses PaintPicture to copy the lines at half their original size. Almost all the lines in the copy show gaps. The horizontal and vertical lines happen to fall along the rows and columns of pixels that were completely removed by PaintPicture, so they are missing entirely. |
|
|
|
|
|
|
|
|
When you enlarge an image, you do not have enough input data to fill in all the output pixels. When you reduce an image, you face the opposite problem: You have too much input data. If you just ignore data as PaintPicture does, you may create aliasing effects. |
|
|
|
|
|
|
|
|
You can prevent these problems by making each output pixel represent the average of its corresponding input pixel values. If you reduce an image to half its original size, for instance, each output pixel corresponds to four input pixels. The value you give the output pixel should be the average of the values of the four input pixels. |
|
|
|
|
|
|
|
|
Every input pixel's value takes part in determining the value of some output pixel, so you do not actually discard any data. Because every input pixel value is represented, you do not lose the larger structure of the image. In particular, you do not get ugly aliasing effects, and you do not create gaps in thin lines. |
|
|
|
|
|
|
|
|
Figure 7.15
PaintPicture can cause gaps in
thin lines and other small features. |
|
|
|
|
|